home *** CD-ROM | disk | FTP | other *** search
- /* lib.c
-
- */
-
- #ifdef THINK_C
- # include "unixlibproto.h"
- #endif THINK_C
-
- #include <stdio.h>
- #include <ctype.h>
- #include <errno.h>
- #include "host.h"
- #ifdef THINK_C
- # include <unix.h>
- # include <fcntl.h>
- #endif
-
- #ifndef NULL
- #define NULL 0L
- #endif
-
- MKDIR( path )
- char * path;
- {
- char * cp = path;
- char *colon, *slash, *sep, sepchar;
- int first = 1;
-
- if ( *cp == '\0' )
- return( 0 );
-
- /* see if we need to make any intermediate directories */
- while (cp && *cp) {
- slash = index (cp, SEPCHAR);
- colon = index (cp, DIRCHAR);
- sep = slash;
- if (colon && (!slash || colon < slash)) {
- sep = colon;
- }
- if (sep) {
- sepchar = *sep;
- if (sepchar != DIRCHAR || !first /* || sep != path */) {
- *sep = '\0';
- mkdir( path );
- *sep = sepchar;
- }
- sep++;
- first = 0;
- }
- cp = sep;
- }
-
- /* make last dir */
- return( mkdir( path ) );
-
- }
-
- CHDIR( path )
- char * path;
- {
- char * cp = path;
-
- if ( *cp == '\0' )
- return( 0 );
-
- MKDIR( path );
-
- /* change to last directory */
- return( chdir( path ) );
-
- }
-
- int OPEN (name, mode)
- char * name;
- int mode;
- {
- char nname[255];
- int results;
- cnvMac(name, nname);
- results = open( nname, mode );
- return results;
- }
-
- FILE * FOPEN( name, mode, ftype )
- char * name;
- char * mode;
- char ftype;
- {
-
- char * last;
- FILE * results;
- char nname[255];
- char opmode[5];
- int len;
-
- /* are we opening for write or append */
-
- FILEMODE( ftype );
- strcpy(opmode, mode);
- if (ftype == 'b') {
- len = strlen(opmode);
- *(opmode+len) = ftype;
- *(opmode+len+1) = '\0';
- }
- #if 0
- DebugStr("\pIn FOPEN");
- #endif
- cnvMac(name, nname);
- results = fopen( nname, opmode );
-
- if ( results != (FILE *) NULL ) { /* fixed [garym 3/21/90 */
- /* success, if not reading, set file info */
- if (*mode != 'r') {
- FInfo fInfo;
- CtoPstr(nname);
- if (GetFInfo((StringPtr)nname, 0, &fInfo) == noErr) {
- fInfo.fdCreator = 'MPS ';
- (void)SetFInfo((StringPtr)nname, 0, &fInfo);
- }
- }
- return( results );
- }
- /* are we opening in sub-directory */
- last = rindex( name, SEPCHAR );
-
- /* lets just verify that all sub-dir's exist */
- if ( last != (char *) NULL ) {
- *last = '\0';
- MKDIR( name );
- *last = '/';
- }
-
- /* now try open again */
- return( fopen( nname, opmode ));
-
- }
-
- int CREAT( name, mode, ftyp )
- char * name;
- int mode;
- char ftyp;
- {
-
- char * last;
- int results;
- char nname[255];
- FILE *fp;
-
- /* are we opening for write or append */
- FILEMODE( ftyp );
- cnvMac(name, nname);
- mode = O_CREAT|O_TRUNC|O_WRONLY; /* ignore Unix perms */
- if (ftyp == 'b') mode |= O_BINARY;
- else mode |= O_TEXT;
- results = creat( nname, mode );
-
- if ( results != -1 )
- return( results ); /* success */
-
- /* are we opening in sub-directory */
- last = rindex( name, '/' );
-
- /* lets just verify that all sub-dir's exist */
- if ( last != (char *) NULL ) {
- *last = '\0';
- MKDIR( name );
- *last = '/';
- }
-
- /* now try open again */
- results = creat( nname, mode );
- if ( results != -1 )
- return( results ); /* success */
-
- /* maybe it already exists, see if we can open it */
- fp = FOPEN( nname, "w", ftyp );
- if ( fp != NULL ) {
- fclose(fp);
- results = 0; /* it already exists, no problem */
- } else {
- results = -1;
- }
-
- return( results );
-
- }
-
- int UNLINK(path)
- char *path;
- {
- char mpath[255];
- cnvMac(path, mpath);
- return(unlink(mpath));
- }
-
-
- extern int debuglevel;
- extern int remote;
-
- #define MASTER 1
-
-
- int getargs( line, flds )
- char *line;
- char **flds;
- {
- int i = 0;
- char *s;
-
- while ( (*line != '\0') && (*line != '\n') )
- {
- if ( isspace(*line) )
- {
- line++;
- continue;
- }
- *flds++ = line;
- i++;
- while( (isspace(*line) == 0) && (*line != '\0') ) line++;
- if (isspace(*line)) *line++ = '\0';
- }
- return(i);
- }
-
-
-